/* 开关组件 - HarmonyOS设计指南实现 */

@import '../base/color.less';
@import '../base/font.less';
@import '../base/window.less';

/* 开关变量 */
:root {
  --switch-width: calc(44 * var(--unit));
  --switch-height: calc(24 * var(--unit));
  --switch-width-small: calc(36 * var(--unit));
  --switch-height-small: calc(20 * var(--unit));
  --switch-width-large: calc(52 * var(--unit));
  --switch-height-large: calc(28 * var(--unit));
  --switch-handle-size: calc(20 * var(--unit));
  --switch-handle-size-small: calc(16 * var(--unit));
  --switch-handle-size-large: calc(24 * var(--unit));
  --switch-border-radius: calc(12 * var(--unit));
  --switch-transition-duration: 0.3s;
  --switch-bg-color-off: var(--color-comp-background-tertiary);
  --switch-bg-color-on: var(--color-brand);
  --switch-handle-color: #ffffff;
  --switch-disabled-opacity: 0.5;
}

/* 基础开关样式 */
.switch {
  position: relative;
  display: inline-block;
  width: var(--switch-width);
  height: var(--switch-height);
  vertical-align: middle;
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
}

.switch-input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
  
  &:checked + .switch-track {
    background-color: var(--switch-bg-color-on);
    
    .switch-handle {
      transform: translateX(calc(var(--switch-width) - var(--switch-handle-size) - calc(4 * var(--unit))));
    }
  }
  
  &:disabled + .switch-track {
    opacity: var(--switch-disabled-opacity);
    cursor: not-allowed;
  }
  
  &:focus-visible + .switch-track {
    outline: 2px solid var(--color-brand);
    outline-offset: 2px;
  }
}

.switch-track {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: var(--switch-bg-color-off);
  border-radius: var(--switch-border-radius);
  transition: background-color var(--switch-transition-duration) ease;
  cursor: pointer;
  overflow: hidden;
}

.switch-handle {
  position: absolute;
  top: calc(2 * var(--unit));
  left: calc(2 * var(--unit));
  width: var(--switch-handle-size);
  height: var(--switch-handle-size);
  background-color: var(--switch-handle-color);
  border-radius: 50%;
  box-shadow: 0 calc(2 * var(--unit)) calc(4 * var(--unit)) rgba(0, 0, 0, 0.2);
  transition: transform var(--switch-transition-duration) ease;
  cursor: pointer;
  z-index: 1;
}

/* 开关尺寸 */
.switch-small,
.switch.small {
  width: var(--switch-width-small);
  height: var(--switch-height-small);
  
  .switch-handle {
    width: var(--switch-handle-size-small);
    height: var(--switch-handle-size-small);
  }
  
  .switch-input:checked + .switch-track .switch-handle {
    transform: translateX(calc(var(--switch-width-small) - var(--switch-handle-size-small) - calc(4 * var(--unit))));
  }
}

.switch-large,
.switch.large {
  width: var(--switch-width-large);
  height: var(--switch-height-large);
  
  .switch-handle {
    width: var(--switch-handle-size-large);
    height: var(--switch-handle-size-large);
    top: calc(2 * var(--unit));
    left: calc(2 * var(--unit));
  }
  
  .switch-input:checked + .switch-track .switch-handle {
    transform: translateX(calc(var(--switch-width-large) - var(--switch-handle-size-large) - calc(4 * var(--unit))));
  }
}

/* 确保尺寸变体中的 handle 正确显示 */
.switch-small .switch-handle,
.switch.small .switch-handle {
  z-index: 1;
}

.switch-large .switch-handle,
.switch.large .switch-handle {
  z-index: 1;
}

/* 开关标签 */
.switch-label {
  display: inline-flex;
  align-items: center;
  gap: calc(8 * var(--unit));
  cursor: pointer;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
  user-select: none;
  
  .switch {
    flex-shrink: 0;
  }
  
  .switch-text {
    font-size: var(--font-size-body-medium);
    color: var(--color-font-primary);
  }
  
  &.switch-label-disabled {
    opacity: var(--switch-disabled-opacity);
    cursor: not-allowed;
    
    .switch-text {
      color: var(--color-font-tertiary);
    }
  }
}

/* 开关变体 */
.switch-success,
.switch.success {
  --switch-bg-color-on: var(--color-confirm);
}

.switch-warning,
.switch.warning {
  --switch-bg-color-on: var(--color-alert);
}

.switch-danger,
.switch.danger {
  --switch-bg-color-on: var(--color-waring);
}

/* 深色模式适配 */
@media (prefers-color-scheme: dark) {
  .switch-handle {
    background-color: var(--switch-handle-color);
  }
  
  .switch-track {
    --switch-bg-color-off: var(--color-comp-background-tertiary);
  }
}

